<template>
  <el-dropdown @command="commandEvent">
    <!--el-dropdown:该标签的默认插槽有限制，不可以有兄弟标签  -->
    <span>
      <svg-icon
        style="color: #fff; font-size: 20px"
        icon-class="language"
      /></span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          command="zh"
          :disabled="$i18n.locale === 'zh'"
        >中文</el-dropdown-item>
        <el-dropdown-item
          command="en"
          :disabled="$i18n.locale === 'en'"
        >English</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
// 国际化-持久化处理
import jsCookie from 'js-cookie'
export default {
  name: 'HmI18n',
  methods: {
    commandEvent(command) {
      //  切换语言
      this.$i18n.locale = command
      jsCookie.set('lang', command)
      // 刷新页面
      this.$router.go(0)
    }
  }
}
</script>

<style lang="scss" scope></style>
